package com.deliveryservicesystem.app.util.filechooser;

import java.io.File;
import javax.swing.ImageIcon;

/**
 * File Name: ChooserUtils.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.app.util.filechooser
 * Author: Lance
 * Date: Jul 28, 2012
 * Editor:
 */
public class ChooserUtils
{

    public final static String xar = "xar";
    public final static String xl = "xl";
    public final static String xla = "xla";
    public final static String xlam = "xlam";
    public final static String xlb = "xlb";
    public final static String xlc = "xlc";
    public final static String xll = "xll";
    public final static String xls = "xls";
    public final static String xlm = "xlm";
    public final static String xlsb = "xlsb";
    public final static String xlsx = "xlsx";
    public final static String xlsm = "xlsm";
    public final static String xlt = "xlt";
    public final static String xltm = "xltm";
    public final static String xltx = "xltx";
    public final static String xlw = "xlw";

    /*
     * Get the extension of a file.
     */
    public static String getExtension(File f)
    {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 && i < s.length() - 1)
        {
            ext = s.substring(i + 1).toLowerCase();
        }
        return ext;
    }

    /**
     * Returns an ImageIcon, or null if the path was invalid.
     */
    protected static ImageIcon createImageIcon(String path)
    {
        java.net.URL imgURL = ChooserUtils.class.getResource(path);
        if (imgURL != null)
        {
            return new ImageIcon(imgURL);
        }
        else
        {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}
